from django.contrib.auth.models import User  # 导入用户表
from django.db import models


# Create your models here.
# 创建班级表
class Classes(models.Model):
    name = models.CharField(max_length=30, verbose_name='班级名')
    slogan = models.TextField(verbose_name='口号', null=True, blank=True)
    create_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
    update_time = models.DateTimeField(verbose_name='更新时间', auto_now=True)
    is_delete = models.BooleanField(default=False, verbose_name='逻辑删除')

    member = models.ManyToManyField(User)  # 将班级和用户做一个多对多的关联

    class Meta:
        db_table = 'classes'  # 表名
        verbose_name = '班级'  # 后台显示的名称
        verbose_name_plural = verbose_name  # 复数名也叫班级

    def delete(self, using=None, keep_parents=False):  # 重写删除方法，逻辑删除
        self.is_delete = True
        self.save()
